<!DOCTYPE html>
<html>
<head>

<link rel="stylesheet" type="text/css" href="../CssFrame/bootstrap-theme.css">
<link rel="stylesheet" type="text/css" href="../CssFrame/bootstrap.css">

<script src="../Jquery/Jquery-3.3.1.js" type="text/javascript"></script>

<meta charset="UTF-8">
<title>登记新访客</title>
</head>
<body>
	<div style="text-align: center;">
		<form id="visi_form" style="margin-top: 42px;">
			<input type="text" id="visitorName" name="visitorName" maxlength="12" placeholder="请输入访客姓名" class="inputclz">
			<br> <br>
			<!--  -->
			<input type="text" id="visitorCardno" name="visitorCardno" maxlength="14" placeholder="请输入访客证件号" class="inputclz">
			<br> <br>
			<!--  -->
			<input type="text" id="visitedStudentName" name="visitedStudentName" maxlength="12" placeholder="请输入被访学生姓名"
				class="inputclz"> <br> <br>
			<!--  -->
			<input type="text" id="visitedStudentBuilding" name="visitedStudentBuilding" maxlength="2" placeholder="请输入被访学生楼号"
				class="inputclz"> <br> <br>
			<!--  -->
			<input type="text" id="visitedStudentChamber" name="visitedStudentChamber" maxlength="4" placeholder="请输入被访学生寝室号"
				class="inputclz"> <br> <br>
			<!--  -->
			<input type="text" id="relation" name="relation" maxlength="1" placeholder="请输入访客与被访者的关系" class="inputclz"> <br>
			<br>
			<!--  -->
			<input type="button" value="确定" id="sub_commit" style="margin-right: 20px;">
			<!--  -->
			<input type="reset" value="重置" id="sub_reset" style="margin-left: 20px;">
		</form>
		<br> <br>
		<div>
			<a href="DormitoryManageSystem.html">返回系统导航页</a>
		</div>
	</div>
</body>

<script type="text/javascript">
	/* */
	$('#sub_commit').click(
			function() {
				/* 正则校验 */
				var visitorCardno = $('#visitorCardno').val();
				var visitorName = $('#visitorName').val();
				var visitedStudentChamber = $('#visitedStudentChamber').val();
				var visitedStudentBuilding = $('#visitedStudentBuilding').val();
				var visitedStudentName = $('#visitedStudentName').val();
				var relation = $('#relation').val();

				if (visitorName == '' || visitorCardno == '' || visitedStudentName == ''
						|| visitedStudentBuilding == '' || visitedStudentChamber == '' || relation == '') {
					alert("未填完");
					return false;
				}

				/*学生楼号格式校验,2位皆为数字*/
				var expression00 = /^\d{2}$/;
				var exp00 = new RegExp(expression00);
				if (exp00.test(visitedStudentBuilding) == false) {
					alert('学生宿舍楼格式错误(请查看是否输入其他字符或长度不足)')
					return;
				}

				/*寝室号格式校验,4位皆为数字*/
				var expression01 = /^\d{4}$/;
				var exp01 = new RegExp(expression01);
				if (exp01.test(visitedStudentChamber) == false) {
					alert('寝室号格式错误(请查看是否输入其他字符或长度不足)');
					return;
				}

				/*  */
				var url = "/dormitory/Visit/add_visitor";
				var data = $("#visi_form").serialize();
				$.ajax({
					"url" : url,
					"data" : data,
					"type" : "POST",
					"dataType" : "json",
					"success" : function(json) {
						if (json.state == 200) {
							alert("登记成功");
							location.href = "DormitoryManageSystem.html";
						} else {
							alert(json.message);
						}
					}
				});
			});

	/* */
	$('#sub_reset').click(function() {
		$(".inputclz").val('')
	});
</script>
</html>